updating oE add

add

include datetime.e -- (default namespace is datetime) 
public function add(datetime dt, object qty, integer interval) 

Adds a number of intervals to a datetime.

Parameters:
  1. dt : the base datetime
  2. qty : the number of intervals to add. It should be positive.
  3. interval : which kind of interval to add.
Returns:

A sequence, more precisely a datetime representing the new moment in time.

Comments:

Please see Constants for Date and Time for a reference of valid intervals.

Do not confuse the item access constants (such as YEAR, MONTH, DAY ) with the interval constants (YEARS, MONTHS, DAYS ).

When adding MONTHS, it is a calendar based addition. For instance, a date of 5/2/2008 with 5 MONTHS added will become 10/2/2008. MONTHS does not compute the number of days per each month and the average number of days per month.

When adding YEARS, leap year is taken into account. Adding 4 YEARS to a date may result in a different day of month number due to leap year.

Example 1:
include std/datetime.e 
 
datetime d1 = now() 
? d1 
datetime d2 = add(d1, 35, SECONDS) -- add 35 seconds to d1 
? d2 
d2 = add(d1, 7, WEEKS)    -- add 7 weeks to d1 
? d2 
d2 = add(d1, 19, YEARS)   -- add 19 years to d1 
? d2 
Results:

{2019,9,8,3,6,49} (yours will vary!)
{2019,9,8,3,7,24}
{2019,10,27,3,6,49}
{2038,9,8,3,6,49}

See Also:

subtract, diff

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu